﻿


using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Threading.Tasks;
using Abp;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.AutoMapper;
using Abp.Configuration;
using Abp.Domain.Repositories;
using Abp.Extensions;
using Abp.Linq.Extensions;
using KDS.Mes.Mes.JitAlcCodes.Dtos;
using KDS.Mes.DataExporting.Excel.EpPlus;
using Abp.Timing.Timezone;
using Abp.Runtime.Session;
using KDS.Mes.Dto;

namespace KDS.Mes.Mes.JitAlcCodes
{
    /// <summary>
    /// Jit生产ALCCode信息的导出EXCEL功能的实现
    /// </summary>
    public class JitAlcCodeListExcelExporter : EpPlusExcelExporterBase, IJitAlcCodeListExcelExporter
    {

        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;


        /// <summary>
        /// 构造方法
        /// </summary>
        public JitAlcCodeListExcelExporter(ITimeZoneConverter timeZoneConverter, IAbpSession abpSession)
        {
            _timeZoneConverter = timeZoneConverter;
            _abpSession = abpSession;
        }



        /// <summary>
        /// 导出Jit生产ALCCode信息到EXCEL文件
        /// <param name="jitAlcCodeListDtos">导出信息的DTO</param>
        /// </summary>
        public FileDto ExportJitAlcCodeToFile(List<JitAlcCodeListDto> jitAlcCodeListDtos)
        {


            var file = CreateExcelPackage("jitAlcCodeList.xlsx", excelPackage =>
            {

                var sheet = excelPackage.Workbook.Worksheets.Add(L("JitAlcCode"));
                sheet.OutLineApplyStyle = true;

                AddHeader(
                    sheet,
                      //L("Style"),
 L("StyleId"),
 //L("AlcCode"),
 L("AlcCodeId"),
 //L("Line"),
 L("LineId"),
 //L("Storage"),
 L("StorageId")
                    );
                AddObjects(sheet, 2, jitAlcCodeListDtos,

             //_ => _.Style,

             _ => _.StyleId,

             //_ => _.AlcCode,

             _ => _.AlcCodeId,

             //_ => _.Line,

             _ => _.LineId,

             //_ => _.Storage,

             _ => _.StorageId

       );
                //写个时间转换的吧
                //var creationTimeColumn = sheet.Column(10);
                //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

                for (var i = 1; i <= 8; i++)
                {
                    sheet.Column(i).AutoFit();
                }

            });
            return file;

        }







    }
}
